package thinking.函数高级

object 偏函数 {
  def main(args: Array[String]): Unit = {

    val value = List(1, 2, 3, 4, "hello")
    //定义偏函数
    val partialFun = new PartialFunction[Any, Int] {
      override def isDefinedAt(x: Any): Boolean = x.isInstanceOf[Int]

      override def apply(v1: Any): Int = {
        v1.asInstanceOf[Int] + 1
      }
    }
    //调动 collect方法,不能使用map
    val value1 = value.collect(partialFun)
    println(value1)

  }

}
